package com.dst.controller;


import com.auth0.jwt.interfaces.DecodedJWT;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dst.entity.Auction;
import com.dst.service.IAuctionService;
import com.dst.utli.JwtUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 董胜涛
 * @since 2022-04-26
 */
@RestController
@RequestMapping("/auction")
public class AuctionController {
  @Resource
  private IAuctionService iAuctionService;
  @RequestMapping("/admin/delete/{id}")
  public void delete(@PathVariable("id") int id,@RequestHeader("authorization") String token){
      iAuctionService.removeById(id);
  }

  @GetMapping("/selectAll")
  public List<Auction> selectAll(){
    List<Auction> list = iAuctionService.list();
    return list;
  }

  @GetMapping("/selectByPage")
  public IPage selectByPage(Page page,Auction auction){
    QueryWrapper<Auction> wrapper = new QueryWrapper<>();
    if(auction!=null){

      if(auction.getAuctionName()!=null&&!"".equals(auction.getAuctionName())){
        wrapper.like("auctionName", auction.getAuctionName());
      }
      if(auction.getAuctionDesc()!=null&&!"".equals(auction.getAuctionDesc())){
        wrapper.like("auctionDesc",auction.getAuctionDesc());
      }
      if(auction.getAuctionStartTime()!=null&&!"".equals(auction.getAuctionStartTime())){
        wrapper.like("auctionStartTime",auction.getAuctionStartTime());
      }
    }

    return iAuctionService.page(page,wrapper);
  }
}
